package com.ruoyi.web.controller.siyun;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.siyun.domain.SyCarousel;
import com.ruoyi.siyun.service.ISyCarouselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 轮播图Controller
 *
 * @author majinyi
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/advertisement/carousel")
public class SyCarouselController extends BaseController
{
    @Autowired
    private ISyCarouselService syCarouselService;

    /**
     * 查询轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('advertisement:carousel:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyCarousel syCarousel)
    {
        startPage();
        List<SyCarousel> list = syCarouselService.selectSyCarouselList(syCarousel);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('advertisement:carousel:export')")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyCarousel syCarousel)
    {
        List<SyCarousel> list = syCarouselService.selectSyCarouselList(syCarousel);
        ExcelUtil<SyCarousel> util = new ExcelUtil<SyCarousel>(SyCarousel.class);
        util.exportExcel(response, list, "轮播图数据");
    }

    /**
     * 获取轮播图详细信息
     */
    @PreAuthorize("@ss.hasPermi('advertisement:carousel:query')")
    @GetMapping(value = "/{carouselId}")
    public AjaxResult getInfo(@PathVariable("carouselId") Long carouselId)
    {
        return success(syCarouselService.selectSyCarouselByCarouselId(carouselId));
    }

    /**
     * 新增轮播图
     */
    @PreAuthorize("@ss.hasPermi('advertisement:carousel:add')")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyCarousel syCarousel)
    {
        return toAjax(syCarouselService.insertSyCarousel(syCarousel));
    }

    /**
     * 修改轮播图
     */
    @PreAuthorize("@ss.hasPermi('advertisement:carousel:edit')")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyCarousel syCarousel)
    {
        return toAjax(syCarouselService.updateSyCarousel(syCarousel));
    }

    /**
     * 删除轮播图
     */
    @PreAuthorize("@ss.hasPermi('advertisement:carousel:remove')")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carouselIds}")
    public AjaxResult remove(@PathVariable Long[] carouselIds)
    {
        return toAjax(syCarouselService.deleteSyCarouselByCarouselIds(carouselIds));
    }
}
